package com.webserver.core;

import com.webserver.http.EmptyRequestException;
import com.webserver.http.HttpRequest;
import com.webserver.http.HttpResponse;

import java.io.*;
import java.net.Socket;
import java.util.HashMap;
import java.util.Map;

public class ClientHandler implements Runnable{
    private Socket socket;
    public  ClientHandler(Socket socket){
        this.socket=socket;
    }
    public void run(){
        try {
            HttpRequest request =new HttpRequest(socket);
            HttpResponse response=new HttpResponse(socket);
            DispatcherServlet servlet =new DispatcherServlet();
            servlet.service(request,response);
            response.flush();
        } catch (IOException e) {
            e.printStackTrace();
        }catch(EmptyRequestException e) {

        }finally{
            try {
                socket.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }

}
